package com.wyd.resourcetj.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import com.wyd.resourcetj.dao.IStatisticsDao;
import com.wyd.resourcetj.model.Statistics;
import com.wyd.resourcetj.util.ChartUtil;
import com.wyd.resourcetj.vo.RoomChartVO;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * StatisticsController
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Resource
    private IStatisticsDao statisticsDao;

    @ApiOperation(value = "添加统计数据",notes="添加统计数据")
	  
    @PostMapping()
      
      public Statistics add(@RequestBody Statistics s) {
          
          return statisticsDao.save(s);
          
      }


      @ApiOperation(value = "根据编号删除统计数据",notes="根据编号删除统计数据")
      @ApiImplicitParam(name="id",value ="统计数据编号",required=true,paramType ="path")
      @DeleteMapping(value ="/{id}")
        public void del(@PathVariable Integer id) {
            
            statisticsDao.deleteById(id);
             
        
            
        }


        @ApiOperation(value = "查询所有统计数据",notes = "查询所有统计数据")
        @PostMapping(value ="/findAll")
        public List<Statistics> findAllStatistics(){
            
           
                List<Statistics> list=new ArrayList<Statistics>();

                list=statisticsDao.findAll();


            return list;
        }


        @ApiOperation(value = "资源室使用统计",notes = "资源室使用统计")
        @GetMapping
        public List<RoomChartVO> getVo(){
            List<Statistics> list =  statisticsDao.findAll();
            //System.out.println(list);
            return ChartUtil.getChart(list);
        }




    
}